package yz.cp.back.s.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import yz.cp.back.s.entity.SysPermission;
import yz.cp.back.s.mapper.SysPermissionMapper;
import yz.cp.back.s.service.ISysPermissionService;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-04-03
 */
@Service
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements ISysPermissionService {

    @Override
    public List<SysPermission> findByUserId(String userId) {
        return this.baseMapper.findByUserId(userId);
    }

    @Override
    public List<SysPermission> findByLevelOrderBySortOrder(Integer level) {
        Wrapper query=new QueryWrapper<SysPermission>().lambda().eq(SysPermission::getLevel,level)
                .orderByAsc(SysPermission::getSortOrder);
        return list(query);
    }

    @Override
    public List<SysPermission> findByParentIdOrderBySortOrder(String parentId) {
        Wrapper query=new QueryWrapper<SysPermission>().lambda().eq(SysPermission::getParentId,parentId)
                .orderByAsc(SysPermission::getSortOrder);
        return list(query); }

    @Override
    public List<SysPermission> findByTypeAndStatusOrderBySortOrder(Integer type, Integer status) {

        Wrapper query=new QueryWrapper<SysPermission>().lambda().eq(SysPermission::getType,type)
                .eq(SysPermission::getStatus,status)
                .orderByAsc(SysPermission::getSortOrder);
        return list(query);
    }

    @Override
    public List<SysPermission> findByTitle(String title) {

        Wrapper query=new QueryWrapper<SysPermission>().lambda().like(SysPermission::getTitle,title);
        return list(query);
    }

    @Override
    public List<SysPermission> findByTitleLikeOrderBySortOrder(String title) {
        Wrapper query=new QueryWrapper<SysPermission>().lambda().like(SysPermission::getTitle,title)
                .orderByAsc(SysPermission::getSortOrder);
        return list(query);
    }
}
